<template>
  <div>
    <!--文章-->
    <div style="margin-top: 60px;margin-bottom: 40px">
      <el-collapse v-for="(article, i) in articleList" :key="i" accordion style="width: 1100px;margin-left: 15%;">

<!--        <el-collapse-item v-if="i<3&&page===1">-->
<!--          <template slot="title">-->
<!--            {{ i+1 }}、{{ article.title }}-->
<!--            <i class="header-icon el-icon-info" style="color: #dd1100;font-size: x-small">hot-->
<!--            </i>-->
<!--            <h5 style="font-size: 10px;color: #dd1100">&nbsp;{{ article.viewNum }}次浏览</h5>-->
<!--          </template>-->
<!--          <div>-->
<!--            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ article.summary }}-->
<!--            <a :href="'/article/'+article.id">-->
<!--              <el-link type="success">详情</el-link>-->
<!--            </a>-->
<!--            <p class="font-content" v-html="article.content">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ article.content }}</p>-->
<!--          </div>-->
<!--        </el-collapse-item>-->

        <el-collapse-item>
          <template slot="title">
            {{ i+1 }}、{{ article.title }}
            &nbsp;
            <h5 v-show="article.difficulty===0" style="font-size: 12px;color: #00AF9B">简单</h5>
            <h5 v-show="article.difficulty===1" style="font-size: 12px;color: #FFB800">中等</h5>
            <h5 v-show="article.difficulty===2" style="font-size: 12px;color: #FF2D55">困难</h5>
            &nbsp;
            <h5 v-show="i<3 && page===1" style="font-size: 10px;color: #dd1100">&nbsp;{{ article.viewNum }}次浏览【new】</h5>
            <h5 v-show="i>2 || page!==1" style="font-size: 10px;color: magenta">&nbsp;{{ article.viewNum }}次浏览</h5>
          </template>
          <div style="color: darkgreen">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ article.summary }}
            <a :href="'/article/'+article.id" target="_blank">
              <el-link type="warning">详情</el-link>
            </a>
            <p class="font-content" v-html="article.content">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ article.content }}</p>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>

    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
    <!--回到顶部-->
    <div>
      <template>
        <el-backtop></el-backtop>
      </template>
    </div>
  </div>
</template>

<script>
import articleApi from '@/api/article'

export default {
  // 写核心代码位置
  data() { // 定义变量和初始值
    return {
      page: 1, // 当前页
      limit: 15, // 每页记录数
      total: 0,
      articleList: []
    }
  },

  created() {
    if (this.$route.params && this.$route.params.id) {

      this.articleClassesId = this.$route.params.id
      console.log("============路由id=============")
      console.log(this.$route.params.id)
      // 调用根据分类id查询方法
      this.getArtilceListByClassesId(this.articleClassesId)
    } else {
      //获取默认列表
      this.getList()
    }
  },

  methods: {

    getList(page = 1) {
      this.page = page // 分页修改参数
      articleApi.getPageArticle(this.page, this.limit)
        .then(response => {

          console.log("============获取文章页列表============")
          console.log(response.data.data)

          this.articleList = response.data.data.items
          this.total = response.data.data.total

        })
    },
  }
}
</script>

<style scoped>
/deep/ .el-collapse-item__header {
  display: flex;
  align-items: center;
  height: 48px;
  line-height: 20px;
  padding: 0px 5px;
  background-color: transparent;
  cursor: pointer;
  font-size: 17px;
  font-weight: 500;
  transition: border-bottom-color .3s;
  outline: none;
  color: #2440BC;
}

/deep/ .el-collapse-item__content {
  padding-bottom: 10px;
  padding-left: 5px;
  font-size: 14px;
  color: #191e34;
  line-height: 1.769230769230769;
}
</style>
<style>
.font-content {
  font-size: large;
  margin-top: 30px;
  margin-left: 4%;
  margin-right: 4%;
}
</style>

